<!DOCTYPE html>
<html lang='zh-CN'>
<head>
    <meta charset="utf-8">
    <meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1, user-scalable=no" />
    <title>指定中奖信息</title>
    <link rel="icon" href="favicon.ico" type="image/ico">
    <link href="css/bootstrap.min.css" rel="stylesheet">
    <link href="css/materialdesignicons.min.css" rel="stylesheet">
    <link href="css/animate.css" rel="stylesheet">
    <link href="css/style.min.css" rel="stylesheet">
    <link href="js/bootstrap-table/bootstrap-table.min.css" rel="stylesheet">
</head>
<body>
<div class="container-fluid p-t-15">
    <div class="row">
        <div class="col-lg-12">
            <div class="card">
                <div class="card-header">
                    <div id="toolbar" class="toolbar-btn-action">
                        <form class="form-inline" method="post" id="searchForm">
                            <div class="form-group">
                                <button class="btn btn-warning btn_query btn-round" type="button" id="editBtn">编辑</button>
                            </div>
                            <div class="form-group">
                                <button class="btn btn-danger btn_query btn-round" type="button" id="deleteBtn">删除</button>
                            </div>
                        </form>
                    </div>
                    <div class="card-body">
                        <table id="grid_data" class="table text-nowrap"></table>
                    </div>
                </div>
            </div>
        </div>
    </div>
</div>

<!-- 指定中奖会员 -->
<div class="modal fade" id="myModal" tabindex="-1" role="dialog" aria-labelledby="myModalLabel">
    <div class="modal-dialog modal-lg" role="document">
        <div class="modal-content">
            <div class="modal-header">
                <button type="button" class="close" data-dismiss="modal" aria-label="Close"><span aria-hidden="true">&times;</span></button>
                <h4 class="modal-title" id="myModalLabel">指定中奖会员</h4>
            </div>
            <div class="modal-body">
                <form class="form-inline" method="post" id="searchCouponForm">
                    <div class="form-group">
                        <label>会员账号:</label>
                        <input type="text" class="form-control" name="memberAccount">
                    </div>
                    <div class="form-group">
                        <button class="btn btn-info btn_query btn-round" type="button" id="searchFormBtn">查询</button>
                    </div>
                </form>
                <div class="tab-content p-10">
                    <table id="member_data" class="table text-nowrap"></table>
                </div>
            </div>
            <div class="modal-footer">
                <button type="button" class="btn btn-default" data-dismiss="modal">取消</button>
                <button type="button" class="btn btn-primary" id="saveBtn">确定</button>
            </div>
        </div>
    </div>
</div>

<script type="text/javascript" src="js/jquery.min.js"></script>
<script type="text/javascript" src="js/bootstrap.min.js"></script>
<script type="text/javascript" src="js/bootstrap-table/bootstrap-table.js"></script>
<script type="text/javascript" src="js/bootstrap-table/bootstrap-table-zh-CN.min.js"></script>
<script type="text/javascript" src="js/zero2one/zero2one.version.js"></script>
<script type="text/javascript" src="js/zero2one/zero2one.core.js"></script>
<!-- bootstrap表单验证插件 -->
<script type="text/javascript" src="js/bootstrapvalidator/dist/js/bootstrapValidator.js"></script>
<!-- bootstrap弹出框插件 -->
<script type="text/javascript" src="js/jquery.bootstrap.min.js"></script>
<!-- 表单填充插件 -->
<script type="text/javascript" src="js/jquery-form/jquery.formloader.js"></script>
<script type="text/javascript" src="js/zero2one/zero2one.curd.js"></script>
<script type="text/javascript">
    //设置表头
    var columnss = [
        {checkbox: true},
        {field: 'memberId',title: '会员ID'},
        {field: 'memberAccount',title: '会员账号'},
        {field: 'nickName',title: '会员昵称'},
        {field: 'memberPhone',title: '手机号码'},
    ];

    //进入主界面加载数据
    zero2one.datagrids("member_data", "/remote/member/list",function (params) {
        return $.extend(zero2one.tableInitParam(params), zero2one.form2json("searchCouponForm"));
    }, columnss,function (data) {});

    //点击查询按钮重新加载页面数据
    $("#searchFormBtn").click(function () {
        $('#member_data').bootstrapTable('refresh');
    });

    //设置表头
    var columns = [
        {checkbox: true},
        {field: 'id',title: '编号'},
        {field: 'memberId',title: '会员ID'},
        {field: 'prizeId',title: '奖品ID'},
        {field: 'prizeName',title: '奖品名称'},
        {field: 'statusId',title: '状态',formatter: function (value, row, index) {
                var checked = value == 1 ? "checked" : "";
                return '<label class="lyear-switch switch-solid switch-success"><input type="checkbox" '+checked+' onclick="status('+value+','+row.id+')"><span></span> '+(value== 1 ? "有效" : "无效")+' </label>'; }},
    ];

    //加载列表信息
    zero2one.table("/remote/prizeWin/list", columns);

    //根据条件查询列表信息
    zero2one.query();

    //点击删除按钮
    zero2one.delete("/remote/prizeWin/delByIds");

    //点击编辑按钮
    $("#editBtn").click(function () {
        var datas = $("#grid_data").bootstrapTable('getSelections');
        if(datas.length == 1){
            $("#myModal").modal("show");
        }else {
            $.messager.alert("温馨提示", "请选择一条数据操作");
        }
    });

    //添加编辑操作
    $("#saveBtn").click(function () {
        var datas = $("#grid_data").bootstrapTable('getSelections');
        var dataes = $("#member_data").bootstrapTable('getSelections');
        if(dataes.length == 1){
            var vo={id:datas[0].id, memberId:dataes[0].memberId};
            $.ajax({ url: '/remote/prizeWin/addOrEdit', contentType:'application/json', type: 'post', data: JSON.stringify(vo), dataType: 'json', success: function (res) {
                    if (res.success) {
                        $.messager.alert("温馨提示", "操作成功,2S之后刷新");
                        setTimeout(function () { window.location.reload(); }, 2000);
                    } else { $.messager.alert("温馨提示", res.msg) }
                }
            });
        }else {
            $.messager.alert("温馨提示", "请选择一名会员操作");
        }
    });

    //修改奖品发放状态
    function status(value,id){
        zero2one. request("/remote/prizeWin/status", {"status": value,"id": id},function (data){
            if (data.success) {
                $.messager.alert("温馨提示", "操作成功");
                $('#grid_data').bootstrapTable('refresh');
            } else { $.messager.alert("温馨提示", data.msg) }
        })
    }

</script>
</div>
</body>
</html>
